package com.wc.算法基础课.A第一讲基础算法.递归.带分数;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/3/13 10:22
 * @description https://www.acwing.com/problem/content/description/1211/
 */
public class Main {
    static boolean[] vis = new boolean[10];
    static boolean[] backup = new boolean[10];
    static int n;
    static int res = 0;

    // n = a + b / c, b = n * c - a * c
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dfsA(0);
        System.out.println(res);
    }

    static void dfsC(int a, int c) {
        if (check(a, c)) res++;

        for (int i = 1; i <= 9; i++) {
            if (!vis[i]) {
                vis[i] = true;
                dfsC(a, c * 10 + i);
                vis[i] = false;
            }
        }
    }

    static void dfsA(int a) {
        if (a >= n) return;
        if (a != 0) dfsC(a, 0);

        for (int i = 1; i <= 9; i++) {
            if (!vis[i]) {
                vis[i] = true;
                dfsA(a * 10 + i);
                vis[i] = false;
            }
        }
    }

    static boolean check(long a, long c) {
        long b = n * c - a * c;
        if (a == 0 || b == 0 || c == 0) return false;
        for (int i = 1; i <= 9; i++) backup[i] = vis[i];
        while (b > 0) {
            long re = b % 10;
            int x = (int) re;
            if (x == 0 || backup[x]) return false;
            backup[x] = true;
            b /= 10;
        }
        for (int i = 1; i <= 9; i++) {
            if (!backup[i]) return false;
        }
        return true;
    }
}
